package ${basePackage}.controller.${modelNameLowerCamel};

import ${basePackage}.application.dto.Result;
import ${basePackage}.application.dto.EmptyDTO;
import ${basePackage}.application.dto.${modelNameLowerCamel}.CreateDTO;
import ${basePackage}.application.dto.${modelNameLowerCamel}.UpdateDTO;
import ${basePackage}.application.seek.IService;
import ${basePackage}.application.service.${modelNameLowerCamel}.*;
import com.alibaba.fastjson.JSONObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * Created by ${author} on ${date}.
 * 描述: ${modelName}控制器
 */
@RestController
@RequestMapping("/${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {

    /**
     * 业务对象
     */
    private IService iService;

    /**
     * 创建
     *
     * @param createDTO
     * @return 传出结果集
     */
    @PostMapping(value = "/${modelRequestMapping}")
    public Result add(@RequestBody @Validated CreateDTO createDTO) {
        iService = new CreateService(createDTO);
        Object json = JSONObject.toJSON(iService.handler());
        return new Result(0, json, "");
    }
    /**
     * 删除
     *
     * @param id 唯一主键
     * @return 传出结果集
     */
    @DeleteMapping(value = "/${modelRequestMapping}/{id}")
    public Result delete(@PathVariable Integer id) {
        iService = new DeleteService(id);
        Object json = JSONObject.toJSON(iService.handler());
        return new Result(0, json, "");
    }
    /**
     * 更新
     *
     * @param id        唯一主键
     * @param updateDTO 更新的内容
     * @return 传出结果集
     */
    @PutMapping(value = "/${modelRequestMapping}/{id}")
    public Result update(@PathVariable Integer id,@RequestBody @Validated UpdateDTO updateDTO) {
        updateDTO.setId(id);
        iService = new UpdateService(updateDTO);
        Object json = JSONObject.toJSON(iService.handler());
        return new Result(0, json, "");
    }
    /**
     * 获取
     *
     * @param id 唯一主键
     * @return 传出结果集
     */
    @GetMapping(value = "/${modelRequestMapping}/{id}")
    public Result detail(@PathVariable Integer id) {
        iService = new GetService(id);
        Object json = JSONObject.toJSON(iService.handler());
        return new Result(0, json, "");
    }
    /**
     * 查询所有
     *
     * @return 传出结果集
     */
    @GetMapping(value = "/${modelRequestMapping}")
    public Result list() {
        iService = new ListService(new EmptyDTO());
        Object json = JSONObject.toJSON(iService.handler());
        return new Result(0, json, "");
    }
}
